<?php

class calendar_model extends CI_Model{

	private $events_table = 'events';

	function get_events($year, $month){
		$this->db->where('date >=', $year.'-'.$month.'-00');
		$this->db->where('date <=', $year.'-'.($month+1).'-00');
		$this->db->order_by('date', 'asc');
		$query = $this->db->get($this->events_table);

		if ($query->num_rows > 0){
			$results = $query->result_array();
			return $results;
		}
	}

	function add_event($data){
		$this->db->insert($this->events_table, $data);
		if (mysql_error() != ''){
			return false;
		} else {
			return true;
		}
	}

	function get_event($id){
		$this->db->where('id', $id);
		$query = $this->db->get($this->events_table);

		if ($query->num_rows == 1){
			$result = $query->row_array();
			return $result;
		}
	}
	
	/**
	 * Updates the event in the database
	 *
	 * @param $event - Array of information for the event table
	 */
	function update_event($event){
		$this->db->where('id', $event['id']);
		$this->db->update($this->events_table, $event);
		
		if (mysql_error() != ''){
			return mysql_error();
		}
	}

}

?>